package br.com.usjt.tcc.schedule.controller;

import java.util.List;

import javax.inject.Inject;

import br.com.caelum.vraptor.Controller;
import br.com.caelum.vraptor.quartzjob.CronTask;
import br.com.usjt.tcc.schedule.interfaces.dao.AnnouncementDao;
import br.com.usjt.tcc.schedule.interfaces.dao.RuleDao;
import br.com.usjt.tcc.schedule.interfaces.dao.UserDao;
import br.com.usjt.tcc.schedule.model.Announcement;
import br.com.usjt.tcc.schedule.model.Rule;
import br.com.usjt.tcc.schedule.model.User;
import br.com.usjt.tcc.schedule.motor.rule.Processador;

@Controller
public class TaskController implements CronTask {

	// http://localhost:8080/PetSchedule/jobs/configure

	@Inject
	RuleDao ruleDao;

	@Inject
	UserDao userDao;

	@Inject
	AnnouncementDao announcementDao;

	@Override
	public void execute() {

		List<Rule> rules = ruleDao.lista();

		List<User> users = userDao.lista();

		Processador processador = new Processador();
		List<Announcement> announcements = processador.getAnnouncments(rules,
				users, announcementDao);

		announcementDao.adiciona(announcements);
	}

	@Override
	public String frequency() {
		// return "*/1 * * * * ?";
		 return "*/5 * * * * ?";

//		return "*/30 * * * * ?";
		// return "*/1 * * * * ?";
		// return "0 0/15 * * * ?";
	}
}
